﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RPAAction
{
    public static class RFC
    {
        /// <summary>
        /// 配置 RFC
        /// </summary>
        /// <param name="appHost">主机地址</param>
        /// <param name="appService">SAP 服务端口号,一般為空</param>
        /// <param name="msgHost">SAP 消息服务器主机地址,如果msgHost有值,则忽略appHost</param>
        /// <param name="msgService">SAP 消息服务器服务端口号,一般為3600</param>
        /// <param name="user">SAP 用户名</param>
        /// <param name="pwd">SAP 密码</param>
        /// <param name="client">SAP 客户端</param>
        /// <param name="language">SAP 登录语言，默认为 "EN"</param>
        /// <param name="timeout">SAP 连接超时时间（单位：秒），默认为 600</param>
        /// <param name="name">SAP 连接名称，默认为 "CNQ"</param>
        /// <param name="funcName">RFC 函数名称</param>
        /// <param name="group">SAP 登录组名称</param>
        public static void SetRFCConf(string appHost, string appService, string msgHost, string msgService, string user, string pwd, string client, string language, string timeout, string name, string funcName, string group)
        {
            CSRFC.CSRFC.SetRFCConf(appHost, appService, msgHost, msgService, user, pwd, client, language, timeout, name, funcName, group);
        }

        /// <summary>
        /// 设置RFC参数
        /// </summary>
        /// <param name="name">参数名称</param>
        /// <param name="value">参数值</param>
        public static void SetValue(string name, string value)
        {
            CSRFC.CSRFC.SetValue(name, value);
        }

        /// <summary>
        /// 将Excel数据写入RFC表
        /// </summary>
        /// <param name="name">表名称</param>
        /// <param name="ExcelPath">Excel路径</param>
        /// <param name="Sheet">Excel工作表</param>
        public static void SetTableFromExcel(string name, string ExcelPath, string Sheet)
        {
            CSRFC.CSRFC.SetTableFromExcel(name, ExcelPath, Sheet);
        }

        /// <summary>
        /// 将Json数据写入RFC表
        /// </summary>
        /// <param name="name">表名称</param>
        /// <param name="json"></param>
        public static void SetTableFromJson(string name, string json)
        {
            CSRFC.CSRFC.SetTableFromJson(name, json);
        }

        /// <summary>
        /// 执行RFC
        /// </summary>
        public static void Invoke()
        {
            CSRFC.CSRFC.Invoke();
        }

        /// <summary>
        /// 获取返回值
        /// </summary>
        /// <param name="name">返回值名称</param>
        /// <returns></returns>
        public static string GetValue(string name)
        {
            return CSRFC.CSRFC.GetValue(name);
        }

        /// <summary>
        /// 获取表导入TXT
        /// </summary>
        /// <param name="rfctable">表名称</param>
        /// <param name="path">文件路径</param>
        /// <param name="delimiter">分隔符,如果为空则判断文件后缀,csv为",",其余默认"\t"</param>
        public static void GetTableToTXT(string rfctable, string path, string delimiter = "", string tagTitle = null, object tagValue = null)
        {
            CSRFC.CSRFC.GetTableToTXT(rfctable, path, delimiter, tagTitle, tagValue);
        }

        /// <summary>
        /// 获取表导入Excel
        /// </summary>
        /// <param name="rfctable"></param>
        /// <param name="ExcelPath"></param>
        /// <param name="Sheet"></param>
        public static void GetTableToExcel(string rfctable, string ExcelPath, string Sheet, string tagTitle = null, object tagValue = null)
        {
            CSRFC.CSRFC.GetTableToExcel(rfctable, ExcelPath, Sheet, tagTitle, tagValue);
        }

        /// <summary>
        /// 获取表导入SqlServer
        /// </summary>
        /// <param name="rfctable"></param>
        /// <param name="DataSource"></param>
        /// <param name="DataBase"></param>
        /// <param name="user"></param>
        /// <param name="pwd"></param>
        /// <param name="table"></param>
        /// <param name="appand">是否附加数据,默认true,否则清空表</param>
        /// <param name="timeout">超时时间(秒),默认1800(半小时),小于0时使用默认值</param>
        public static void GetTableToSqlServer(string rfctable, string DataSource, string DataBase, string user, string pwd, string table, bool appand = true, decimal timeout = 0, string tagTitle = null, object tagValue = null)
        {
            CSRFC.CSRFC.GetTableToSqlServer(rfctable, DataSource, DataBase, user, pwd, table, appand, timeout, tagTitle, tagValue);
        }
    }
}
